home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / xlib / xlib06p2 / xbmtools.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-23  |  1.6 KB  |  70 lines

  1. #include "xdefs.h"
  2. #include "xbmtools.h"
  3.  
  4. /*
  5. ;-----------------------------------------------------------------------
  6. ; x_pbm_to_bm
  7. ;
  8. ; This function converts a bitmap in the planar format to the linear format
  9. ; as used by x_compile_bitmap.
  10. ;
  11. ; WARNING: the source and destination bitmaps must be pre - allocated
  12. ;
  13. ; NOTE: This function can only convert planar bitmaps that are suitable.
  14. ;       If the source planar bitmap's width (per plane) is >= 256/4
  15. ;       it cannot be converted. In this situation an error code
  16. ;       BM_WIDTH_ERROR. On successful conversion 0 is returned.
  17. ;
  18. ; C callable as:
  19. ;    int x_pbm_to_bm(char far * source_pbm, char far * dest_bm);
  20. ;
  21. ; Written By Themie Gouthas
  22.  
  23. //  converted to C++ by Maciej Kalisiak
  24.  
  25. */
  26.  
  27. int x_pbm_to_bm( char * pbm, char * lbm)
  28. {
  29.     WORD width=pbm[0]<<2;
  30.     WORD height=pbm[1];
  31.     
  32.     if( width>255 )
  33.         return 1;
  34.  
  35.     lbm[0]=width;
  36.     lbm[1]=pbm[1];
  37.  
  38.     WORD size=width*height;
  39.     for( WORD offs=0;offs<size;offs++ )
  40.         *(lbm+ 2+ (offs*4)%size+ (offs*4)/size)=pbm[offs+2];
  41.  
  42.     return 0;
  43. }
  44.  
  45. int x_bm_to_pbm( char * lbm, char * pbm )
  46. {
  47.     WORD width=lbm[0];
  48.     WORD height=lbm[1];
  49.     
  50.     pbm[0]=width>>2;
  51.     pbm[1]=lbm[1];
  52.  
  53. //    WORD offs=0;
  54. //    for( WORD y=0;y<height;y++ )
  55. //      for( WORD x=0;x<width;x+=4 )
  56. //      {
  57. //          lbm[offs+2]=*(pbm+ 2+ y*width+ x);
  58. //          offs++;
  59. //      }
  60.  
  61.     WORD size=width*height;
  62.     for( WORD offs=0;offs<size;offs++ )
  63.         pbm[offs+2]=*(lbm+ 2+ (offs*4)%size+ (offs*4)/size);
  64.  
  65.     return 0;
  66. }
  67.  
  68.  
  69.  
  70.